<!-- List of activieties  -->
        <script type="text/javascript">
        /* <![CDATA[ */ 
        function selectAll(checkbox){
            var inputs = $('activities_list').getElementsByTagName('input');
                if(checkbox.checked){
                    for(i=0;i<inputs.length;i++) inputs[i].checked=true;
                }
                else{
                    for(i=0;i<inputs.length;i++) inputs[i].checked=false;
                }
        }
        /* ]]> */
        </script>

        <% form_tag({:controller => 'invoices', :action => 'add_activities'}) do %>
        
        <table class="standard" id="activities_list">
       
        <tr>
            <th> Project</th>
            <th> Person</th>
            <th> Date </th>
            <th> Hours </th>
	    <%- if(!@selected.nil? and @selected['details']) -%>
	      <th> Comment </th>
	    <%- end -%>
            <td>&nbsp;</td>
             <td>&nbsp;</td>
        </tr>

        <% minutes_sum=0
        not_only_invoiced=false 	 
        for activity in @activities  
        minutes_sum+=activity.minutes 
        activity.invoice_id.blank? ? not_only_invoiced=true : "" %>
        <tr>
            <td>					<%= link_to activity.project.name, :controller => 'projects', :action => 'show', :id => activity.project %></td>
            <td>					<%= link_to activity.user.login, :controller => 'users', :action => 'show', :id => activity.user %>				
                (<%= activity.user.role.short_name.upcase %>)</td>
            <td style="text-align: center"><%= h activity.date %></td>
            <td style="text-align: right"><%= hour_format(activity.minutes) %></td>
	    <% if(@selected and @selected['details']) %>
	      <td><%= truncate(activity.comments,15) %></td>
	    <% end %>
            <td><%= link_to image_tag("show.png", :alt=>"Show", :title=>"Show"), {:controller => "activities", :action => "show", :id => activity}, :class=>"nobg" %></td>
            <td style="text-align:center">
            <%= check_box_tag("activity_id[]", activity.id, false, :id => nil) if(!params[:search].nil? and activity.invoice_id.blank?) %>
            </td>
            </tr>
        <% end %>
        
        <tr>
            <td colspan="2"></td>
            <th style="text-align: right">Sum:</th>
            <th><%= hour_format(minutes_sum) %></th>
            <td style="text-align:right"><%= "all" if(!params[:search].nil? and not_only_invoiced==true) %></td>
            <td style="text-align:center">
            <%= check_box_tag("select_all", 1, false, {:id => nil, :onclick=>"selectAll(this)"}) if(!params[:search].nil? and not_only_invoiced==true) %>
            </td>
        </tr>
        

        <tr>
            <td colspan="6" id="invoices_list">
            <%= render :partial => '/activities/invoices_list' if(!@invoices.nil? and !@invoices.empty? and not_only_invoiced==true)%>
            </td>
         </tr>
         <tr id="add_new_invoice">
            <td colspan="6">
            <% unless params[:search].nil? -%>
            <% if(!@invoices.nil? and !@invoices.empty? and not_only_invoiced==true) -%>
            <span style="font-size:smaller;"><%= link_to_remote "Add new invoice",:update => "add_invoice_form", :url => {:controller => 'invoices', :action => 'add_new', :client_id => @client_id} %></span>
            <% elsif params[:search][:project_id].blank? -%>
            <span style="font-size:smaller;color:red;background-color:inherit">No project specified!</span>
            <% elsif(params[:search][:is_invoiced]=="2" or not_only_invoiced==false) -%>
            <span style="font-size:smaller;color:red;background-color:inherit">Only invoiced activities found!</span>
            <% else -%>
            <span style="font-size:smaller;color:red;background-color:inherit">No active invoices found for this client!          
            <br/><%= link_to_remote "Add new invoice",:update => "add_invoice_form", :url => {:controller => 'invoices', :action => 'add_new', :client_id => @client_id} %></span>
            <% end -%>
            <% end -%>
            
            </td>
        </tr>

        </table>
        <% end %>
        <div id="add_invoice_form"></div>
        <%= paginate_me @activities %>
<!-- End of list -->

